<template>
  <div class="add_table_css">
    <el-button plain @click="addEducation" class="btn_css_newadd">新增学历信息</el-button>
    <!-- 新增学历信息的弹框 -->
    <el-dialog title="新增学历信息" :visible.sync="dialogFormVisible" width="40%" center>
      <el-form
        label-width="80px"
        :model="eduTable"
        :rules="rules"
        ref="eduTable"
        class="demo-ruleForm add_education_css"
      >
        <el-form-item label="毕业院校" prop="graduationSchool">
          <el-input v-model="eduTable.graduationSchool"></el-input>
        </el-form-item>
        <el-form-item label="入学时间" prop="entranceTime">
          <!-- <el-date-picker type="date" placeholder="1987-09-23" v-model="eduTable.entranceTime"></el-date-picker> -->
          <el-date-picker
            v-model="eduTable.entranceTime"
            type="date"
            placeholder="选择日期"
            format="yyyy 年 MM 月 dd 日"
            value-format="timestamp"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="毕业时间" prop="graduationTime">
          <!-- <el-date-picker type="date" placeholder="1987-09-23" v-model="eduTable.graduationTime"></el-date-picker> -->
          <el-date-picker
            v-model="eduTable.graduationTime"
            type="date"
            placeholder="选择日期"
            format="yyyy 年 MM 月 dd 日"
            value-format="timestamp"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="所学专业" prop="major">
          <el-input v-model="eduTable.major"></el-input>
        </el-form-item>
        <el-form-item label="学制">
          <el-input v-model="eduTable.educationalSystem"></el-input>
        </el-form-item>
        <el-form-item label="学习形式">
          <el-select v-model="eduTable.learningForm">
            <el-option label="自学" value="自学"></el-option>
            <el-option label="报班" value="报班"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-select v-model="eduTable.education">
            <el-option label="本科" value="本科"></el-option>
            <el-option label="硕士" value="硕士"></el-option>
            <el-option label="大专" value="大专"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学位" prop="academic">
          <el-select v-model="eduTable.academic">
            <el-option label="本科" value="本科"></el-option>
            <el-option label="硕士" value="硕士"></el-option>
            <el-option label="大专" value="大专"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer add_footer_btn_css">
        <el-button plain @click="addOk('eduTable')" class="btn_css_bord">保存</el-button>
         <!-- <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button> -->
        <el-button plain @click="dialogFormVisible = false" class="btn_css_bord">关闭</el-button>
      </div>
    </el-dialog>
    <!-- 表格 -->
    <el-container>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="index" label="序号" width="50"></el-table-column>
        <el-table-column prop="entranceTime" label="入学时间" width="120"></el-table-column>
        <el-table-column prop="graduationTime" label="毕业时间" width="120"></el-table-column>
        <el-table-column prop="graduationSchool" label="毕业院校" width="120"></el-table-column>
        <el-table-column prop="major" label="所学专业" width="280"></el-table-column>
        <el-table-column prop="education" label="学历" width="100"></el-table-column>
        <el-table-column prop="academic" label="学位" width="120"></el-table-column>
        <el-table-column label="操作" width="250">
          <template slot-scope="scope">
            <el-button @click="see(scope.$index, tableData)" plain size="small" class="btn_css_er">查看</el-button>
            <el-button
              @click.native.prevent="update(scope.$index, tableData)"
              plain
              size="small"
              class="btn_css_er"
            >修改</el-button>
            <el-button
              @click.native.prevent="del(scope.$index, tableData)"
              plain
              size="small"
              class="btn_css_er"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-container>
    <!-- 查看信息的弹框 -->
    <el-dialog title="查看学历信息" :visible.sync="dialogFormVisible2" width="40%" center>
      <el-form
        label-width="80px"
        :model="eduTable2"
        :rules="rules"
        ref="eduTable2"
        class="demo-ruleForm add_education_css"
      >
        <el-form-item label="毕业院校" prop="graduationSchool">
          <el-input v-model="eduTable2.graduationSchool" disabled></el-input>
        </el-form-item>
        <el-form-item label="入学时间" prop="entranceTime">
          <el-input v-model="eduTable2.entranceTime" disabled></el-input>
        </el-form-item>
        <el-form-item label="毕业时间" prop="graduationTime">
          <el-input v-model="eduTable2.graduationTime" disabled></el-input>
        </el-form-item>
        <el-form-item label="所学专业" prop="major">
          <el-input v-model="eduTable2.major" disabled></el-input>
        </el-form-item>
        <el-form-item label="学制">
          <el-input v-model="eduTable2.educationalSystem" disabled></el-input>
        </el-form-item>
        <el-form-item label="学习形式">
          <el-input v-model="eduTable2.learningForm" disabled></el-input>
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-input v-model="eduTable2.education" disabled></el-input>
        </el-form-item>
        <el-form-item label="学位" prop="academic">
          <el-input v-model="eduTable2.academic" disabled></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 修改信息的弹框 -->
    <el-dialog title="修改学历信息" :visible.sync="dialogFormVisible3" width="40%" center>
      <el-form
        label-width="80px"
        :model="eduTable3"
        :rules="rules"
        ref="eduTable3"
        class="demo-ruleForm add_education_css"
      >
        <el-form-item label="毕业院校" prop="graduationSchool">
          <el-input v-model="eduTable3.graduationSchool"></el-input>
        </el-form-item>
        <el-form-item label="入学时间" prop="entranceTime">
          <!-- <el-input v-model="eduTable3.entranceTime"></el-input> -->
          <!-- <el-date-picker type="date" v-model="eduTable3.entranceTime"></el-date-picker> -->
          <el-date-picker
            v-model="eduTable3.entranceTime"
            type="date"
            placeholder="选择日期"
            format="yyyy 年 MM 月 dd 日"
            value-format="timestamp"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="毕业时间" prop="graduationTime">
          <!-- <el-input v-model="eduTable3.graduationTime"></el-input> -->
          <!-- <el-date-picker type="date" v-model="eduTable3.graduationTime"></el-date-picker> -->
          <el-date-picker
            v-model="eduTable3.graduationTime"
            type="date"
            placeholder="选择日期"
            format="yyyy 年 MM 月 dd 日"
            value-format="timestamp"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="所学专业" prop="major">
          <el-input v-model="eduTable3.major"></el-input>
        </el-form-item>
        <el-form-item label="学制">
          <el-input v-model="eduTable3.educationalSystem"></el-input>
        </el-form-item>
        <el-form-item label="学习形式">
          <el-select v-model="eduTable3.learningForm">
            <el-option label="自学" value="自学"></el-option>
            <el-option label="报班" value="报班"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-select v-model="eduTable3.education">
            <el-option label="本科" value="本科"></el-option>
            <el-option label="硕士" value="硕士"></el-option>
            <el-option label="大专" value="大专"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学位" prop="academic">
          <el-select v-model="eduTable3.academic">
            <el-option label="本科" value="本科"></el-option>
            <el-option label="硕士" value="硕士"></el-option>
            <el-option label="大专" value="大专"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer add_footer_btn_css">
        <el-button plain @click="updateOk('eduTable3')" class="btn_css_bord">保存</el-button>
        <!-- <el-button plain @click="updateOk('eduTable')" class="btn_css_bord">保存</el-button> -->
        <el-button plain @click="dialogFormVisible3 = false" class="btn_css_bord">关闭</el-button>
      </div>
    </el-dialog>
    <!-- 分页 -->
    <div class="block page_css">
      <el-pagination
        layout="prev, pager, next"
        :total="total"
        :page-size="limit"
        @current-change="change"
        @prev-click="prev"
        @next-click="next"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      page: 1,
      limit: 5,
      total: 0,
      staffId: 1,
      tableData: [],
      dialogFormVisible: false,
      dialogFormVisible2: false,
      dialogFormVisible3: false,
      eduTable: {
        graduationSchool: "",
        major: "",
        educationalSystem: "",
        learningForm: "",
        education: "",
        academic: "",
        entranceTime: "",
        graduationTime: ""
      },
      rules: {
        graduationSchool: [
          { required: true, message: "请输入毕业院校", trigger: "blur" }
        ],
        entranceTime: [
          { required: true, message: "请选择入学时间", trigger: "change" }
        ],
        graduationTime: [
          { required: true, message: "请选择毕业时间", trigger: "change" }
        ],
        major: [{ required: true, message: "请输入所学专业", trigger: "blur" }],
        education: [
          { required: true, message: "请选择学历", trigger: "change" }
        ],
        academic: [{ required: true, message: "请选择学位", trigger: "change" }]
      },

      eduTable2: {
        graduationSchool: "",
        major: "",
        educationalSystem: "",
        learningForm: "",
        education: "",
        academic: "",
        entranceTime: "",
        graduationTime: ""
      },
      eduTable3: {
        graduationSchool: "",
        major: "",
        educationalSystem: "",
        learningForm: "",
        education: "",
        academic: "",
        entranceTime: "",
        graduationTime: ""
      }
    };
  },
  methods: {
    /* 页面渲染 */
    getCon() {
      this.$axios({
        url: "/education/findByWhere",
        params: {
          staffId: this.staffId,
          page: this.page,
          limit: this.limit
        }
      }).then(res => {
        // console.log(res);
        this.tableData = res.data.data;
        this.total = res.data.count;
      });
    },
    /* 查看 */
    see(index, data) {
      this.dialogFormVisible2 = true;
      
      this.eduTable2 = { ...data[index]};
    },
    /* 新增 */
    addEducation() {
      this.dialogFormVisible = true;
    },
    addOk(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
             this.$axios({
            url: "/education/add",
            method: "post",
            data: {
              staffId: this.staffId,
              graduationSchool: this.eduTable.graduationSchool,
              major: this.eduTable.major,
              educationalSystem: this.eduTable.educationalSystem,
              learningForm: this.eduTable.learningForm,
              education: this.eduTable.education,
              academic: this.eduTable.academic,
              entranceTime: this.eduTable.entranceTime,
              graduationTime: this.eduTable.graduationTime
            }
          }).then(res => {
            console.log(res);
            this.getCon();
            this.$message.success('添加成功！');
            this.dialogFormVisible = false;
          });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },


    /* 修改 */
    update(index, data) {
      this.dialogFormVisible3 = true;
      this.eduTable3 = { ...data[index]};
    },
    updateOk(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$axios({
            url: "/education/update",
            method: "post",
            data: {
              eId: this.eduTable3.eId,
              graduationSchool: this.eduTable3.graduationSchool,
              major: this.eduTable3.major,
              education: this.eduTable3.education,
              academic: this.eduTable3.academic,
              entranceTime: this.eduTable3.entranceTime,
              graduationTime: this.eduTable3.graduationTime,
              educationalSystem:this.eduTable3.educationalSystem,
              learningForm:this.eduTable3.learningForm
            }
          }).then(res => {
            // console.log(res);
            this.getCon();
            this.$message.success('修改成功！');
            this.dialogFormVisible3 = false;
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    /* 删除 */
    del(index, data) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$axios({
            url: "/education/delete",
            method: "post",
            data: {
              eId: data[index].eId
            }
          }).then(() => {
            this.$message.success('删除成功!');
            this.getCon();
          });
        })

        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    
    
    
    
    /* 分页渲染 */
    change(page) {
      this.page = page;
      this.getCon();
    },
    prev() {
      this.page--;
      this.getCon();
    },
    next() {
      this.page++;
      this.getCon();
    },
    

  },
  mounted() {
    this.getCon();
  }
};
</script>
<style scoped lang="less">
.page_css {
  margin: 10px;
  text-align: right;
}
.el-table {
  font-size: 13px;
}
.btn_css_newadd {
  background-color: #f7f7f7;
  border: 1px solid #eee;

  text-align: center;
}
.btn_css_er {
  background-color: #f7f7f7;
  border: 1px solid #eee;
  width: 60px;
  height: 30px;
  text-align: center;
}
.btn_css_bord {
  background-color: #f7f7f7;
  border: 1px solid #eee;
  width: 80px;
  height: 40px;
  font-size: 14px;
  text-align: center;
}
.add_education_css {
  width: 300px;
  margin: 0 auto;
}
.add_footer_btn_css {
  margin: 0 auto;
}
.add_table_css {
  border: 1px solid #eee;
  height: 600px;
  padding: 20px;
}
</style>